﻿using Gallio.Framework;
using MbUnit.Framework;
using BitTorrent.Bencode;
using BitTorrent.Bencode.Collections;
using BitTorrent.Bencode.Exceptions;

namespace UnitTests.Bencode
{
    /// <summary>
    /// Summary description for DictionaryTests
    /// </summary>
    [TestFixture]
    public class DictionaryTests
    {
        [Test]
        public void DecodeDictionaryOk() {
            var actual = BencodeFactory.Decode(System.Text.Encoding.UTF8.GetBytes("d1:ai0ee"));
            Assert.IsTrue(actual is Dictionary);

            var dictonary = (Dictionary)actual;

            Assert.IsTrue(((Integer)dictonary["a"]).Value == 0);
        }

        [Test]
        [ExpectedException(typeof(BencodeException))]
        public void DecodeDictionaryWithoutByteStringAsKey() {
            var actual = BencodeFactory.Decode(System.Text.Encoding.UTF8.GetBytes("di3ee8ee"));
        }

        [Test]
        [ExpectedException(typeof(BencodeException))]
        public void DecodeDictionaryWithOddNumberOfElements() {
            var actual = BencodeFactory.Decode(System.Text.Encoding.UTF8.GetBytes("d1:ai0e1:be"));
        }
    }
}
